<template>
  <div class="item">
    <img @click="gotoPro(pro.pid)" :src="'/companys/' + ranPic" alt="" />
    <p @click="gotoPro(pro.pid)">{{ pro.pname }}</p>
    <div>
      <img src="@/assets/img/money11859.png" alt="" />
      <span @click="gotoCom(pro.company)">{{ comName }}</span>
    </div>
    <div>
      <span>￥</span>
      <h4>{{ pro.price }}</h4>
      <span>￥{{ pro.price * 2 }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      comName: null,
    }
  },
  methods: {
    getComData() {
      const url = "/companys/proCom?pid=" + this.pro.pid
      this.axios.get(url).then((res) => {
        // console.log(res)
        this.comName = res.data.data[0].cname
      })
    },
    gotoPro(pid) {
      this.$router.push("/pro_details?pid=" + pid)
    },
    gotoCom(company) {
      this.$router.push("/company?cid=" + company)
    },
  },
  computed: {
    ranPic() {
      let picList = this.pro.pics.split("=")
      //   console.log(picList)
      let index = Math.floor(Math.random() * picList.length)
      return picList[index]
    },
  },
  props: {
    pro: {
      required: true,
    },
  },
  mounted() {
    this.getComData()
  },
}
</script>

<style lang="scss" scoped>
.item {
  width: 100%;
  > img {
    width: 100%;
    cursor: pointer;
    &:hover {
      opacity: 0.8;
    }
  }
  > p {
    font-size: 13px;
    margin-top: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: 0.5s;
    cursor: pointer;
    &:hover {
      color: #e4464b;
    }
  }
  > div:nth-child(3) {
    display: flex;
    align-items: center;
    margin-top: 7px;
    > img {
      height: 17px;
      margin-right: 4px;
    }
    > span {
      font-size: 8px;
      color: #666;
      cursor: pointer;
      &:hover {
        text-decoration: underline;
      }
    }
  }
  > div:nth-child(4) {
    color: #e4464b;
    display: flex;
    align-items: center;
    margin-top: 8px;
    > span:first-child {
      display: block;
      font-weight: bold;
      font-size: 15px;
    }
    > span:nth-child(3) {
      display: block;
      text-decoration: line-through;
      color: #999;

      margin-left: 10px;
      font-size: 6px;
    }
  }
}
</style>
